package com.multycopy;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.LayoutStyle;

public class MCNewCopy extends JDialog {

	private static final long serialVersionUID = 1L;
	@SuppressWarnings( "unused" )
	private JFrame parent;
	private JDialog window;
	private JButton btnSourceFile;
    private JButton btnDestinFile;
    private JButton btnAccept;
    private JButton btnCancel;
    private JCheckBox chkMove;
    private JLabel lblSourceFile;
    private JLabel lblDestinFile;
    private JTextField txtSourceFile;
    private JTextField txtDestinFile;
	
    public MCNewCopy( JFrame parent, boolean modal) {
        super( parent, modal );
        
        this.parent = parent;
        this.window = this;
        this.setSize( 563, 172 );
        this.setResizable( false );
        this.setName( "New copy operation" );
        this.getLblSourceFile();
        this.getLblDestinFile();
        this.getTxtSourceFile();
        this.getTxtDestinFile();
        this.getChkMove();
        this.getBtnSourceFile();
        this.getBtnDestinFile();
        this.getBtnAccept();
        this.getBtnCancel();
        
        initComponents();
        
        this.setVisible( true );
    }

    private JLabel getLblSourceFile() {
    	if( this.lblSourceFile == null ) {
    		this.lblSourceFile = new JLabel( "Source file:" );
    	}
    	
    	return this.lblSourceFile;
    }
    
    private JLabel getLblDestinFile() {
    	if( this.lblDestinFile == null ) {
    		this.lblDestinFile = new JLabel( "Destination file:" );
    	}
    	
    	return this.lblDestinFile;
    }
    
    private JTextField getTxtSourceFile() {
    	if( this.txtSourceFile == null ) {
    		this.txtSourceFile = new JTextField();
    	}
    	
    	return this.txtSourceFile;
    }
    
    private JTextField getTxtDestinFile() {
    	if( this.txtDestinFile == null ) {
    		this.txtDestinFile = new JTextField();
    	}
    	
    	return this.txtDestinFile;
    }
    
    private JButton getBtnSourceFile() {
    	if( this.btnSourceFile == null ) {
    		this.btnSourceFile = new JButton( "···" );
    	}
    	
    	return this.btnSourceFile;
    }
    
    private JButton getBtnDestinFile() {
    	if( this.btnDestinFile == null ) {
    		this.btnDestinFile = new JButton( "···" );
    	}
    	
    	return this.btnDestinFile;
    }
    
    private JButton getBtnAccept() {
    	if( this.btnAccept == null ) {
    		this.btnAccept = new JButton( "Accept" );
    	}
    	
    	return this.btnAccept;
    }
    
    private JButton getBtnCancel() {
    	if( this.btnCancel == null ) {
    		this.btnCancel = new JButton( "Cancel" );
    		
    		this.btnCancel.addActionListener( new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					window.setVisible( false );
				}
    		});
    	}
    	
    	return this.btnCancel;
    }
    
    private JCheckBox getChkMove() {
    	if( this.chkMove == null ) {
    		this.chkMove = new JCheckBox( "Delete file on finish (Move)" );
    	}
    	
    	return this.chkMove;
    }
    
    private void initComponents() {
    	this.rootPane.registerKeyboardAction( new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				window.setVisible( false );
			}
    	}, KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), JComponent.WHEN_IN_FOCUSED_WINDOW );
    	    	
        GroupLayout layout = new GroupLayout( getContentPane() );
        this.getContentPane().setLayout( layout );
        
        layout.setHorizontalGroup(
            layout.createParallelGroup( GroupLayout.Alignment.LEADING )
            .addGroup( layout.createSequentialGroup()
                .addContainerGap()
                .addGroup( layout.createParallelGroup( GroupLayout.Alignment.TRAILING )
                    .addGroup( layout.createSequentialGroup()
                        .addGroup( layout.createParallelGroup( GroupLayout.Alignment.TRAILING )
                            .addComponent( this.lblSourceFile )
                            .addComponent( this.lblDestinFile ) )
                        .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED )
                        .addGroup( layout.createParallelGroup( GroupLayout.Alignment.LEADING, false )
                            .addComponent( this.txtSourceFile, GroupLayout.PREFERRED_SIZE, 349, GroupLayout.PREFERRED_SIZE )
                            .addComponent( this.chkMove )
                            .addComponent( this.txtDestinFile ) ) )
                    .addComponent( this.btnCancel ) )
                .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED )
                .addGroup( layout.createParallelGroup( GroupLayout.Alignment.LEADING )
                    .addComponent( this.btnAccept )
                    .addComponent( this.btnSourceFile )
                    .addComponent( this.btnDestinFile ) )
                .addContainerGap( GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ) )
        );
        
        layout.setVerticalGroup(
            layout.createParallelGroup( GroupLayout.Alignment.LEADING )
            .addGroup( layout.createSequentialGroup()
                .addContainerGap()
                .addGroup( layout.createParallelGroup( GroupLayout.Alignment.BASELINE )
                    .addComponent( this.txtSourceFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE )
                    .addComponent( this.btnSourceFile )
                    .addComponent( this.lblSourceFile ) )
                .addPreferredGap( LayoutStyle.ComponentPlacement.UNRELATED )
                .addGroup( layout.createParallelGroup( GroupLayout.Alignment.BASELINE )
                    .addComponent( this.lblDestinFile )
                    .addComponent( this.txtDestinFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE )
                    .addComponent( this.btnDestinFile ) )
                .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED )
                .addComponent( this.chkMove )
                .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED )
                .addGroup( layout.createParallelGroup( GroupLayout.Alignment.BASELINE )
                    .addComponent( this.btnAccept )
                    .addComponent( this.btnCancel ) )
                .addContainerGap( GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ) )
        );

        pack();
    }
}